package com.zhanglu.fun.services.datacenter.entity;

import com.zhanglu.fun.services.datacenter.user.UserMapper;
import com.zhanglu.fun.services.datacenter.util.SpringUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;

/**
 * user实体类
 *
 * @author jingmb
 */
@Getter
@Setter
@ToString(callSuper = true)
@ApiModel(value = "用户数据模型")
public class User extends BaseDomain<User> {
    @ApiModelProperty("账号")
    private String username;
    @ApiModelProperty("密码")
    private String password;
    @ApiModelProperty("昵称")
    private String nickName;
    @ApiModelProperty("邮箱")
    private String email;
    @ApiModelProperty("性别")
    private Boolean gender;
    @ApiModelProperty("年龄")
    private Integer age;
    @ApiModelProperty("身份证号")
    private String idCard;

    @Transient
    private UserMapper userMapper;

    public User(){
        userMapper = (UserMapper) SpringUtil.getBean("userMapper");
    }

    @Override
    public List<User> list() {
        return userMapper.select(this);
    }

    @Override
    public Boolean delete() {
        return userMapper.deleteByPrimaryKey(this.getId()) > 0;
    }

    @Override
    public Boolean add() {
        return userMapper.insert(this) > 0;
    }

    @Override
    public Boolean update() {
        return userMapper.updateByPrimaryKeySelective(this) > 0;
    }
}
